package com.giraffe.device.api.factory;

import com.giraffe.device.api.DeviceService;
import com.giraffe.device.pojo.dto.DeviceDTO;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Slf4j
@Component
public class DeviceFallbackFactory implements FallbackFactory<DeviceService> {
    private static final Logger log = LoggerFactory.getLogger(DeviceFallbackFactory.class);

    @Override
    public DeviceService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new DeviceService() {

            @Override
            public DeviceDTO getDevice(String deviceId) {
                log.info("-----获取设备DTO失败--------");
                return null;
            }

            @Override
            public Boolean setDeviceStatus(DeviceDTO dto) {
                log.info("-----设置设备状态失败--------");
                return null;
            }
        };
    }
}
